package source.events.action;

import source.model.*;
import source.model.utility.*;
import source.model.type.*;
import source.view.MainScreen;

public class MoveCursor implements Action{


	private MoveDirection mvDirection;

	public MoveCursor(MoveDirection mvDirection){
		this.mvDirection = mvDirection;
	}

	public ActionResult execute(DataHandler dh){
		    Position currentPos = dh.getCurrentPosition();
		    if(currentPos == null)
		    {
		    	//MainScreen.writeToConsole("MoveCursor:  Current position is null");
		    	return ActionResult.IMPOSSIBLE;
		    }
			int x = currentPos.getX() + mvDirection.xChange();
			int y = currentPos.getY() + mvDirection.yChange();
			
			Position ret = new Position(x, y);
			if(ret.isValid()){
				dh.setCurrentPosition(ret);
				return ActionResult.SUCCESS;
			}
			else
			{
				MainScreen.writeToConsole("Target position is invalid");
				return ActionResult.IMPOSSIBLE;
			}
	}
}
